<template>
    <div class="common-page page-corp-companys" v-loading.fullscreen="loading">
        <div class="common-page__head">
            <!-- <comp-paths class="route" :paths="['/corp', $route.fullPath]"></comp-paths> -->
            <div class="title">{{ $options.title }}</div>
        </div>
        <comp-companys class="common-page__body" ref="list" select link>
            <template #head="scope">
                <el-button type="plain" size="small" icon="el-icon-refresh" @click="search()">刷新列表</el-button>
                <el-button type="primary" size="small" icon="el-icon-plus" @click="addCompany()">添加企业/项目</el-button>
                <el-button type="danger" size="small" icon="el-icon-delete" @click="delCompany(...scope.selects)">删除企业/项目</el-button>
                <el-button type="plain" size="small" icon="el-icon-upload2" @click="importCompanys()">导入企业/项目</el-button>
                <el-dropdown trigger="click">
                    <el-button type="plain" size="small" icon="el-icon-download">导出企业/项目</el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item @click.native="exportCompanys()">导出企业/项目信息</el-dropdown-item>
                        <el-dropdown-item @click.native="exportCompanysAttendances()">导出企业/项目走访记录</el-dropdown-item>
                        <el-dropdown-item @click.native="exportCompanysUsed()">导出企业/项目使用情况</el-dropdown-item>
                        <el-dropdown-item @click.native="exportCompanysOrders()">导出企业/项目事项信息</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <el-button type="plain" size="small" icon="el-icon-setting" @click="setCompanysStatus('start', scope.selects)">审核企业/项目</el-button>
            </template>
            <template #body="scope">
                <el-button type="primary" size="mini" @click.stop="getCompany(scope.data)">详情</el-button>
                <el-button type="danger" size="mini" @click.stop="delCompany(scope.data)">删除</el-button>
            </template>
        </comp-companys>
        <comp-dialog title="添加企业/项目" ref="company">
            <el-form size="small" label-width="140px" style="margin-right: 20px" @submit.native.prevent v-if="company">
                <el-form-item label="企业/项目LOGO：">
                    <img style="display: block; margin: 0 10px 10px 0; max-width: 120px; height: 60px" :src="company.logo" v-if="company.logo" />
                    <el-button type="plain" icon="el-icon-plus" @click="addCompany('upload-logo')">{{ company.logo ? "更换图片" : "选择图片" }}</el-button>
                </el-form-item>
                <el-form-item label="企业/项目类型：" required>
                    <el-select v-model="company.type" style="width: 480px" @change="addCompany('validate')">
                        <el-option v-for="data in env.companyTypes" :key="data.id" :label="data.name" :value="data.value">{{ data.name }}</el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="统一社会信用代码：" label-width="160px" >
                    <el-input ref="xydm" v-model="xydm" style="width: 460px" placeholder="请输入" :maxlength="100" @change="addCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="企业/项目名称：" required>
                    <el-input ref="companyName" v-model="company.name" style="width: 480px" placeholder="请输入" :maxlength="100" :readonly="loading" @change="addCompany('validate')"></el-input>
                </el-form-item>

                <el-form-item label="企业/项目简介：">
                    <el-input type="textarea" v-model="company.desc" style="width: 480px" placeholder="请输入" :rows="2" resize="none" :readonly="loading" @change="addCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="所在地址：" required>
                    <el-select v-model="company.province.id" style="margin-right: 10px; width: 160px" placeholder="省份" @change="addCompany('validate')">
                        <el-option v-for="data in provinces" :key="data.id" :label="data.name" :value="data.id"></el-option>
                    </el-select>
                    <el-select v-model="company.city.id" style="margin-right: 10px; width: 150px" placeholder="城市" clearable @change="addCompany('validate')">
                        <template v-for="data in citys">
                            <el-option :key="data.id" :label="data.name" :value="data.id" v-if="data.province.id === company.province.id"></el-option>
                        </template>
                    </el-select>
                    <el-select v-model="company.county.id" style="width: 150px" placeholder="县区" clearable @change="addCompany('validate')">
                        <template v-for="data in countys">
                            <el-option :key="data.id" :label="data.name" :value="data.id" v-if="data.city.id === company.city.id"></el-option>
                        </template>
                    </el-select>
                    <div style="margin-top: 10px"></div>
                    <el-input v-model="company.location.address" style="width: 480px" placeholder="详细地址" :maxlength="100" :readonly="loading" @change="addCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="地址坐标：">
                    <el-input v-model="company.location.coord" style="width: 392px" placeholder="请输入" :readonly="loading" @change="addCompany('validate')"></el-input>
                    <el-tag style="margin-left: 10px" disable-transitions>
                        <span>坐标拾取</span>
                        <a style="position: absolute; top: 0; left: 0; width: 100%; height: 100%" href="https://lbs.qq.com/tool/getpoint/index.html" target="_blank"></a>
                    </el-tag>
                </el-form-item>
                <el-form-item label="法定代表人：">
                    <el-input v-model="company.owner" style="width: 480px" placeholder="请输入" :maxlength="100" :readonly="loading" @change="addCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="企业/项目规模：">
                    <el-select v-model="company.size" style="width: 480px" placeholder="请选择" @change="addCompany('validate')">
                        <el-option v-for="data in env.companySizes" :key="data.id" :label="data.name" :value="data.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所属行业：" required>
<!--                     <el-select v-model="company.industry.name" style="width: 480px" placeholder="请选择" @change="addCompany('validate')">-->
<!--                        <el-option key="0" label="第一产业（农、林、牧、渔业）" value="第一产业（农、林、牧、渔业）"></el-option>-->
<!--                        <el-option key="1" label="工业" value="工业"></el-option>-->
<!--                        <el-option key="2" label="建筑业" value="建筑业"></el-option>-->
<!--                        <el-option key="3" label="第三产业（服务业）" value="第三产业（服务业）"></el-option>-->
<!--                    </el-select>-->
                    <el-cascader
                        v-model="company.industryIds"
                        :options="industryTreeData"
                        :props="{label:'name',value:'id'}"
                    />
                </el-form-item>
                <el-form-item label="企业性质：">
                     <el-select v-model="qyxz" style="width: 480px" placeholder="请选择" @change="addCompany('validate')">
                        <el-option key="0" label="国有控股" value="国有控股"></el-option>
                        <el-option key="1" label="民营企业" value="民营企业"></el-option>
                        <el-option key="2" label="外资企业" value="外资企业"></el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item label="服务小组：">
                    <el-select v-model="company.fwxz" style="width: 480px" placeholder="请选择" @change="addCompany('validate')">
                        <el-option key="17" label="市县自主调研" value="市县自主调研"></el-option>

                        <el-option key="0" label="第一组" value="第一组"></el-option>
                        <el-option key="1" label="第二组" value="第二组"></el-option>
                        <el-option key="2" label="第三组" value="第三组"></el-option>
                        <el-option key="3" label="第四组" value="第四组"></el-option>
                        <el-option key="4" label="第五组" value="第五组"></el-option>
                        <el-option key="5" label="第六组" value="第六组"></el-option>
                        <el-option key="6" label="第七组" value="第七组"></el-option>
                        <el-option key="7" label="第八组" value="第八组"></el-option>
                        <el-option key="8" label="第九组" value="第九组"></el-option>
                        <el-option key="9" label="第十组" value="第十组"></el-option>
                        <el-option key="10" label="第十一组" value="第十一组"></el-option>
                        <el-option key="11" label="第十二组" value="第十二组"></el-option>
                        <el-option key="12" label="第十三组" value="第十三组"></el-option>
                        <el-option key="13" label="第十四组" value="第十四组"></el-option>
                        <el-option key="14" label="第十五组" value="第十五组"></el-option>
                        <el-option key="15" label="第十六组" value="第十六组"></el-option>
                        <el-option key="16" label="第十七组" value="第十七组"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所属分类：">
                    <el-select v-model="company.tag.id" style="width: 480px" placeholder="请选择" @change="addCompany('validate')">
                        <el-option v-for="data in tags" :key="data.id" :label="data.name" :value="data.id"></el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="主管工作队：">
                    <el-tag v-for="dept in company.depts" :key="dept.id" style="margin: 0 10px 10px 0" disable-transitions>{{ dept.name }}</el-tag>
                    <div v-if="company.depts.length > 0"></div>
                    <el-button type="plain" icon="el-icon-plus" @click="addCompany('pick-dept-start')">选择工作队</el-button>
                    <el-button type="plain" icon="el-icon-delete" @click="addCompany('clear-depts')" v-if="company.depts.length > 0">清空</el-button>
                </el-form-item> -->
<!--                <el-form-item label="审核状态：">-->
<!--                    <el-select v-model="company.status" style="width: 160px" placeholder="请选择" @change="addCompany('validate')">-->
<!--                        <el-option v-for="data in env.companyStatus" :key="data.id" :label="data.name" :value="data.value"></el-option>-->
<!--                    </el-select>-->
<!--                </el-form-item>-->
                <el-form-item>
                    <el-button type="primary" icon="el-icon-check" @click="addCompany('submit')">添加</el-button>
                    <el-button type="plain" icon="el-icon-close" @click="addCompany('end')">放弃</el-button>
                </el-form-item>
            </el-form>
        </comp-dialog>
        <comp-dialog title="从 Excel 导入企业/项目" width="360px" ref="companysImportForm">
            <comp-import template="./data/CorpDetailImportTemplate.xlsx" @start="importCompanys('submit', $event)" @end="importCompanys('end')"></comp-import>
        </comp-dialog>
        <comp-dialog title="选择工作队" width="720px" height="80vh" ref="deptPicker">
            <comp-depts style="height: 100%" ref="deptPickerList" v-if="company">
                <template #body="scope">
                    <el-button type="primary" size="mini" icon="el-icon-check" @click.stop="addCompany('pick-dept-end', scope.data)" v-if="(scope.data.type === 'team' || scope.data.type === 'office') && scope.data.city.id === company.city.id && company.city.id">选择</el-button>
                </template>
                <template #foot="scope">
                    <el-button type="danger" size="small" icon="el-icon-close" @click="addCompany('pick-dept-end')">放弃</el-button>
                </template>
            </comp-depts>
        </comp-dialog>
        <comp-dialog title="批量审核企业/项目" ref="companysStatusSetForm">
            <el-form size="small" label-width="98px" style="margin-right: 20px" @submit.native.prevent>
                <el-form-item label="审核数量：" required>
                    <div style="width: 240px">已勾选的{{ companysStatusSetForm.companys.length }}个企业/项目</div>
                </el-form-item>
                <el-form-item label="审核状态：" required>
                    <el-select v-model="companysStatusSetForm.status" style="width: 240px" placeholder="请选择" @change="setCompanysStatus('validate')">
                        <el-option v-for="data in env.companyStatus" :key="data.id" :label="data.name" :value="data.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-check" @click="setCompanysStatus('submit')">确定审核</el-button>
                    <el-button type="plain" icon="el-icon-close" @click="setCompanysStatus('end')">取消</el-button>
                </el-form-item>
            </el-form>
        </comp-dialog>
    </div>
</template>

<script>
    import mixin from "../mixin";
    import { string, int, float, deepCopy, toMagicImgURL, selectFile } from "../util";
    import {getSysIndustryList} from '@/api/industry'
    import treeData from '@/plugins/treeData'
    export default {
        name: "page-corp-companys",
        title: "企业/项目管理",
        nodes: ["/menu/corp"],
        childs: ["corp-company", "corp-company-orders", "corp-company-attendances", "corp-company-demands", "corp-company-products", "corp-company-feedbacks"],
        mixins: [mixin],
        data: () => ({
            loading: false,
            company: null,
            provinces: [],
            citys: [],
            countys: [],
            industrys: [],
            xydm:null,
            qyxz:null,
            tags: [],
            companysImportForm: {
                file: null,
                name: "",
                size: "",
            },
            companysStatusSetForm: {
                companys: [],
                status: "",
            },
            industryTreeData:[]
        }),
        methods: {
            search() {
                if (this.loading) return;
                this.$nextTick(() => this.$refs.list.init());
            },
            addCompany(action, data) {
                if (this.loading) return;
                let form = this.company;
                let provinces = this.provinces = this.plugins.user.provinces;
                let citys = this.citys = this.plugins.user.citys;
                let countys = this.countys = this.plugins.user.countys;
                let industrys = this.industrys;
                let tags = this.tags;
                if (!action || action === "start") {
                    getSysIndustryList({
                        id_exp:[
                            { exp: "in", value: "202316872581980012,202216420729294108,202216575009104433,202316872582170014" ,parameterType:'Long'},
                        ],
                    }).then(res=>{
                        console.log('getSysIndustryList',res)
                        if(res?.data?.list){
                            this.industryTreeData = treeData.arrayToTree(res.data.list,'id','parentId','')
                        }
                    })
                    this.loading = true;
                    this.plugins.user.call(async () => {
                        if (industrys.length > 0) return { code: 0 };
                        let res = await this.plugins.user.getCompanyOfIndustrys({ linage: 1000, page: 1 });
                        if (res.code === 0) this.industrys = res.data.list;
                        return res;
                    }, async () => {
                        if (tags.length > 0) return { code: 0 };
                        let res = await this.plugins.user.getCompanyOfTags({ linage: 100, page: 1 });
                        if (res.code === 0) this.tags = res.data.list;
                        return res;
                    }).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.company = this.plugins.user.formatCompany();
                            this.company.type = "company";
                            this.company.province.id = "450000";
                            this.company.status = "approved";
                            this.addCompany("validate");
                            this.$refs.company.init();
                            this.$nextTick(() => this.$refs.xydm.focus());
                        } else {
                            this.plugins.modal.toast("加载失败<br>" + res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "validate") {
                    let error = "";


                    form.name = string(form.name).trim();
                    // error = error || (form.xydm ? "" : "请输入统一社会信用代码！");
                    form.xydm = this.xydm;
                    form.qyxz = this.qyxz;


                    error = error || (form.name ? "" : "请输入企业/项目名称！");
                    error = error || (form.industryIds?.length > 0 ? "" : "所属行业必填！");

                    form.desc = string(form.desc);
                    form.fwxz = string(form.fwxz);
                    form.qyxz = string(form.qyxz);

                    form.province.id = string(() => provinces.find((province) => province.id === form.province.id).id);
                    form.city.id = string(() => citys.find((city) => city.id === form.city.id && city.province.id === form.province.id).id);
                    form.county.id = string(() => countys.find((county) => county.id === form.county.id && county.city.id === form.city.id).id);
                    error = error || (form.province.id && form.city.id && form.county.id ? "" : "请完善所在地址！");
                    form.location.address = string(form.location.address).trim();
                    form.location.coord = string(form.location.coord).trim();
                    form.location.lng = Math.min(Math.max(float(form.location.coord.split(",")[1], 6), 0), 180);
                    form.location.lat = Math.min(Math.max(float(form.location.coord.split(",")[0], 6), 0), 90);
                    form.location.coord = form.location.lng > 0 && form.location.lat > 0 ? form.location.lat + "," + form.location.lng : "";
                    form.owner = string(form.owner).trim();
                    form.industry.name = string(form.industry.name).trim();
                    if (data) this.plugins.modal.toast(error, "error");

                    return !error;
                } else if (action === "upload-logo") {
                    if (!data) return selectFile("image/*").then((file) => {
                        if (file.size > 5 * 1048576) this.plugins.modal.toast("图片过大，不能大于5MB哦！请重新选择。", "error");
                        else this.addCompany(action, file);
                    });
                    let timer = null;
                    let progress = (event) => timer = clearTimeout(timer) || setTimeout(() => this.plugins.modal.toast("上传进度：" + event.percent + "%", "info"), 200);
                    this.loading = true;
                    this.plugins.user.uploadFile(data, "image", progress).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            form.logo = toMagicImgURL(res.data.value, 120, 120);
                            this.addCompany("validate");
                        } else {
                            this.plugins.modal.alert("图片上传失败", res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "pick-dept-start") {
                    this.$refs.deptPicker.init();
                    this.$nextTick(() => this.$refs.deptPickerList.init());
                } else if (action === "pick-dept-end") {
                    if (data && form.depts.findIndex((dept) => dept.id === data.id) === -1) form.depts.push(data);
                    this.addCompany("validate");
                    this.$refs.deptPicker.close();
                } else if (action === "clear-depts") {
                    form.depts.splice(0);
                    this.addCompany("validate");
                } else if (action === "submit") {
                    if (!this.addCompany("validate", true)) return;
                    this.loading = true;
                    this.plugins.user.addCompany(form).then((res) => {

                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.toast("添加成功！", "success");
                            this.addCompany("end");
                            this.search();
                        } else {
                            this.plugins.modal.alert("添加失败", res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "end") {
                    this.$refs.company.close();
                }
            },
            getCompany(company) {

                if (this.loading) return;
                this.$router.push("/corp/company?companyId=" + company.id);
            },
            delCompany(...companys) {
                if (this.loading) return;
                if (companys.length === 0) return this.plugins.modal.toast("请先勾选要删除的企业/项目哦！", "warning");
                let content = " <span style='color:red;'>" + (companys.length > 1 ? "勾选的" + companys.length + "个企业/项目" : companys[0].name) + "</span> 吗？";
                this.plugins.modal.alert("删除确认", "确定删除" + content, "warning", ["确定删除", "再想想"]).then((ok) => {
                    if (!ok) return;
                    this.loading = true;
                    this.plugins.user.delCompany(...companys).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.toast("删除成功！", "success");
                            this.search();
                        } else {
                            this.plugins.modal.alert("删除失败", res.code + "：" + res.msg, "error");
                        }
                    });
                });
            },
            importCompanys(action, data) {
                if (this.loading) return;
                if (!action || action === "start") {
                    this.$refs.companysImportForm.init();
                } else if (action === "submit") {
                    this.loading = true;
                    this.plugins.user.importCompanys({ file: data }).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.alert("导入任务创建成功！", "任务执行需要花费一些时间，可稍后再点击右上角打开“系统任务”查看任务状态。", "success", ["查看任务状态", "稍后查看"]).then((ok) => ok && this.$router.push("/user/tasks"));
                            this.importCompanys("end");
                            this.search();
                        } else {
                            this.plugins.modal.alert("导入失败", res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "end") {
                    this.$refs.companysImportForm.close();
                }
            },
            exportCompanys() {
                if (this.loading) return;
                let filters = deepCopy(this.$refs.list.filters);
                let content = "当前筛选条件下的 <span style='color:red;'>全部共" + filters.total + "个企业/项目</span> ";
                if (filters.ids && filters.ids.length > 0) content = " <span style='color:red;'>已勾选的" + filters.ids.length + "个企业/项目</span> ";
                let callback = () => {
                    this.loading = true;
                    this.plugins.user.exportCompanys(filters).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.alert("导出任务创建成功！", "任务执行需要花费一些时间，可稍后再点击右上角打开“系统任务”查看任务状态。", "success", ["查看任务状态", "稍后查看"]).then((ok) => ok && this.$router.push("/user/tasks"));
                        } else {
                            this.plugins.modal.alert("导出失败", res.code + "：" + res.msg, "error");
                        }
                    });
                };
                this.plugins.modal.alert("批量导出", "确定导出" + content + "吗？", "warning", ["确定导出", "再想想"]).then((ok) => ok && callback());
            },
            setCompanysStatus(action, data) {
                if (this.loading) return;
                let form = this.companysStatusSetForm;
                if (!action || action === "start") {
                    let companys = data;
                    if (companys.length === 0) return this.plugins.modal.toast("请先勾选需要审核的企业/项目！", "warning");
                    form.companys = companys;
                    form.status = "approved";
                    this.setCompanysStatus("validate");
                    this.$refs.companysStatusSetForm.init();
                } else if (action === "validate") {
                    let error = "";
                    if (data) this.plugins.modal.toast(error, "error");
                    return !error;
                } else if (action === "submit") {
                    if (!this.setCompanysStatus("validate", true)) return;
                    this.loading = true;
                    this.plugins.user.setCompanysStatus(form.companys, form.status).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.toast("操作成功！", "success");
                            this.setCompanysStatus("end");
                            this.search();
                        } else {
                            this.plugins.modal.alert("操作失败", res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "end") {
                    this.$refs.companysStatusSetForm.close();
                }
            },
            exportCompanysAttendances() {
                if (this.loading) return;
                let filters = deepCopy(this.$refs.list.filters);
                let content = "当前筛选条件下的 <span style='color:red;'>全部共" + filters.total + "个企业/项目的走访记录</span> ";
                if (filters.ids && filters.ids.length > 0) content = " <span style='color:red;'>已勾选的" + filters.ids.length + "个企业/项目的走访记录</span> ";
                let callback = () => {
                    this.loading = true;
                    this.plugins.user.exportCompanysAttendances(filters).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.alert("导出任务创建成功！", "任务执行需要花费一些时间，可稍后再点击右上角打开“系统任务”查看任务状态。", "success", ["查看任务状态", "稍后查看"]).then((ok) => ok && this.$router.push("/user/tasks"));
                        } else {
                            this.plugins.modal.alert("导出失败", res.code + "：" + res.msg, "error");
                        }
                    });
                };
                this.plugins.modal.alert("批量导出", "确定导出" + content + "吗？", "warning", ["确定导出", "再想想"]).then((ok) => ok && callback());
            },
            exportCompanysUsed() {
                if (this.loading) return;
                let filters = deepCopy(this.$refs.list.filters);
                let content = "当前筛选条件下的 <span style='color:red;'>全部共" + filters.total + "个企业/项目的使用情况</span> ";
                if (filters.ids && filters.ids.length > 0) content = " <span style='color:red;'>已勾选的" + filters.ids.length + "个企业/项目的使用情况</span> ";
                let callback = () => {
                    this.loading = true;
                    this.plugins.user.exportCompanysUsed(filters).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.alert("导出任务创建成功！", "任务执行需要花费一些时间，可稍后再点击右上角打开“系统任务”查看任务状态。", "success", ["查看任务状态", "稍后查看"]).then((ok) => ok && this.$router.push("/user/tasks"));
                        } else {
                            this.plugins.modal.alert("导出失败", res.code + "：" + res.msg, "error");
                        }
                    });
                };
                this.plugins.modal.alert("批量导出", "确定导出" + content + "吗？", "warning", ["确定导出", "再想想"]).then((ok) => ok && callback());
            },
            exportCompanysOrders() {
                if (this.loading) return;
                let filters = deepCopy(this.$refs.list.filters);
                let content = "当前筛选条件下的 <span style='color:red;'>全部共" + filters.total + "个企业/项目的事项信息</span> ";
                if (filters.ids && filters.ids.length > 0) content = " <span style='color:red;'>已勾选的" + filters.ids.length + "个企业/项目的事项信息</span> ";
                let callback = () => {
                    this.loading = true;
                    this.plugins.user.exportCompanysOrders(filters).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.plugins.modal.alert("导出任务创建成功！", "任务执行需要花费一些时间，可稍后再点击右上角打开“系统任务”查看任务状态。", "success", ["查看任务状态", "稍后查看"]).then((ok) => ok && this.$router.push("/user/tasks"));
                        } else {
                            this.plugins.modal.alert("导出失败", res.code + "：" + res.msg, "error");
                        }
                    });
                };
                this.plugins.modal.alert("批量导出", "确定导出" + content + "吗？", "warning", ["确定导出", "再想想"]).then((ok) => ok && callback());
            },
            destroy() {
                if (this.loading) return;
                return true;
            },
            init() {
                if (this.loading) return;
                this.loading = true;
                this.$root.$refs.navbar.init();
                this.plugins.user.call(async () => {
                    let res = await this.plugins.user.init();
                    if (res.code === 0) { }
                    return res;
                }, async () => {
                    if (this.access(this.$route.name)) return { code: 0 };
                    return this.env.xhrErrors.find((error) => error.code === 4);
                }).then((res) => {
                    this.loading = false;
                    this.$root.$refs.navbar.init();
                    if (res.code === 0) {
                        this.search();
                    } else if (res.code === 2) {
                        this.$root.$refs.navbar.login();
                    } else {
                        this.plugins.modal.alert("页面加载失败", res.code + "：" + res.msg, "error").then(() => this.$router.replace("/home"));
                    }
                });
            },
        },
    };
</script>

<style lang="scss">
    .page-corp-companys {
        overflow: hidden;
    }
</style>
